<template>
  <div>
    <el-form ref="goods" :model="form" :rules="rules" size="medium" label-width="200px">
      <el-form-item label="商品编号id" prop="goodsProductId">
        <el-input v-model="form.goodsProductId" placeholder="请输入商品编号id" clearable :style="{width: '300px'}">
        </el-input>
      </el-form-item>
      <el-form-item label="商品名称" prop="goodsProductName">
        <el-input v-model="form.goodsProductName" placeholder="请输入商品名称" clearable :style="{width: '300px'}">
        </el-input>
      </el-form-item>
      <el-form-item label="商品的供应商id" prop="goodsSupplierId">
        <el-input v-model="form.goodsSupplierId" placeholder="请输入商品的供应商id" clearable :style="{width: '300px'}">
        </el-input>
      </el-form-item>
      <el-form-item label="商品的原产地" prop="goodsOriginalProductionPlace">
        <el-input v-model="form.goodsOriginalProductionPlace" placeholder="请输入商品的原产地" clearable
          :style="{width: '300px'}"></el-input>
      </el-form-item>
      <el-form-item label="商品的生产日期" prop="goodsProductionDate">
        <el-date-picker v-model="form.goodsProductionDate" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
          :style="{width: '300px'}" placeholder="请选择商品的生产日期" clearable></el-date-picker>
      </el-form-item>
      <el-form-item label="商品的实际进货地" prop="goodsPurchasePlace">
        <el-input v-model="form.goodsPurchasePlace" placeholder="请输入商品的实际进货地" clearable
          :style="{width: '300px'}"></el-input>
      </el-form-item>
      <el-form-item label="商品进货日期" prop="goodsPurchaseDate">
        <el-date-picker v-model="form.goodsPurchaseDate" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
          :style="{width: '300px'}" placeholder="请选择商品进货日期" clearable></el-date-picker>
      </el-form-item>
      <el-form-item label="商品保质期" prop="goodsShelfLife">
        <el-input v-model="form.goodsShelfLife" placeholder="请输入商品保质期" clearable :style="{width: '300px'}">
        </el-input>
      </el-form-item>
      <el-form-item label="商品的进货单价价格" prop="goodsPurchaseUnitPrice">
        <el-input-number v-model="form.goodsPurchaseUnitPrice" placeholder="商品的进货单价价格" :precision='2'>
        </el-input-number>
      </el-form-item>
      <el-form-item label="商品的出售单价价格" prop="goodsSellingUnitPrice">
        <el-input-number v-model="form.goodsSellingUnitPrice" placeholder="商品的出售单价价格" :precision='2'>
        </el-input-number>
      </el-form-item>
      <el-form-item size="large">
        <el-button type="primary" @click="submitForm">提交</el-button>
        <el-button @click="resetForm">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import request from "@/utils/request";

export default {
  components: {},
  props: [],
  data() {
    return {
      form: {
        goodsProductId: undefined,
        goodsProductName: undefined,
        goodsSupplierId: undefined,
        goodsOriginalProductionPlace: undefined,
        goodsProductionDate: null,
        goodsPurchasePlace: undefined,
        goodsPurchaseDate: null,
        goodsShelfLife: undefined,
        goodsPurchaseUnitPrice: undefined,
        goodsSellingUnitPrice: undefined,
      },
      rules: {
        goodsProductId: [{
          required: true,
          message: '请输入商品编号id',
          trigger: 'blur'
        }],
        goodsProductName: [{
          required: true,
          message: '请输入商品名称',
          trigger: 'blur'
        }],
        goodsSupplierId: [{
          required: true,
          message: '请输入商品的供应商id',
          trigger: 'blur'
        }],
        goodsOriginalProductionPlace: [{
          required: true,
          message: '请输入商品的原产地',
          trigger: 'blur'
        }],
        goodsProductionDate: [{
          required: true,
          message: '请选择商品的生产日期',
          trigger: 'change'
        }],
        goodsPurchasePlace: [{
          required: true,
          message: '请输入商品的实际进货地',
          trigger: 'blur'
        }],
        goodsPurchaseDate: [{
          required: true,
          message: '请选择商品进货日期',
          trigger: 'change'
        }],
        goodsShelfLife: [{
          required: true,
          message: '请输入商品保质期',
          trigger: 'blur'
        }],
        goodsPurchaseUnitPrice: [{
          required: true,
          message: '商品的进货单价价格',
          trigger: 'blur'
        }],
        goodsSellingUnitPrice: [{
          required: true,
          message: '商品的出售单价价格',
          trigger: 'blur'
        }],
      },
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    submitForm() {
      this.$refs['goods'].validate(valid => {
        if (!valid) return
        addGoods(this.formData).then(response => {
          this.$modal.msgSuccess("新增成功");
        });
        // TODO 提交表单
      })
    },
    resetForm() {
      this.$refs['goods'].resetFields()
    },
  }
}
// 新增商品
export function addGoods(data) {
  return request({
    url: '/goods/goods',
    method: 'post',
    data: data
  })
}
</script>
<style>
</style>
